<extend name="Public/base"/>

<block name="body">
	<script type="text/javascript" src="__STATIC__/ColorPicker/jquery.js"></script>
	<script type="text/javascript" src="__STATIC__/ColorPicker/jquery.colorpicker.js"></script>
	<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2>添加商品</h2>
    </div>
    <ul class="tab-nav nav">
        <li class="current"><a href="javascript:void(0)">基本信息</a></li>
    </ul>
    <form action="{:U()}" method="post" class="form-horizontal">
    <div class="tab-content">
        <div class="form-item">
            <label class="item-label">所属商户</label>
            <div class="controls">
                <input type="text" class="text input-large" readonly="readonly" value="{$shop_name}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">商品名称</label>
            <div class="controls">
                <input type="text" class="text input-large" name="goods_name" value="">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">商品分类</label>
            <div class="controls">
                <select name="goods_type" style="width:200px;">
                    {:R('Goods/tree', array($tree))}
                </select>
            </div>
        </div>
        <div class="form-item">
            <div class="controls">
                <label class="item-label">商品图片</label>
                <input type="file" id="upload_picture">
                <input type="hidden" name="goods_img" id="goods_img" value="{$info['goods_img']|default=''}"/>
                <div class="upload-img-box">
                    <notempty name="goods_img['goods_img']">
                        <div class="upload-pre-item"><img src="__ROOT__{$info.goods_img|get_cover='path'}"/></div>
                    </notempty>
                </div>
            </div>
            <script type="text/javascript">
                //上传图片
                /* 初始化上传插件 */
                $("#upload_picture").uploadify({
                    "height"          : 30,
                    "swf"             : "__STATIC__/uploadify/uploadify.swf",
                    "fileObjName"     : "download",
                    "buttonText"      : "上传图片",
                    "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                    "width"           : 120,
                    'removeTimeout'	  : 1,
                    'fileTypeExts'	  : '*.jpg; *.png; *.gif;*.jpeg;',
                    "onUploadSuccess" : uploadPicture,
                    'onFallback' : function() {
                        alert('未检测到兼容版本的Flash.');
                    }
                });
                function uploadPicture(file, data){
                    var data = $.parseJSON(data);
                    var src = '';
                    if(data.status){
                        var icon=$("#goods_img").val();
                        if(icon){
                            $("#goods_img").val(icon+','+data.id);
                        }else {
                            $("#goods_img").val(data.id);
                        }
                        src = data.url || '__ROOT__' + data.path;
                        var html=$("#goods_img").parent().find('.upload-img-box').html();
                        if(html){
                            $("#goods_img").parent().find('.upload-img-box').html(
                                html+ '<div class="upload-pre-item"><img src="' + src + '"/></div><span class="span1" uid="'+data.id+'">x</span>'
                            );
                        }else {
                            $("#goods_img").parent().find('.upload-img-box').html(
                                '<div class="upload-pre-item"><img src="' + src + '"/></div><span class="span1" uid="'+data.id+'">x</span>'
                            );
                        }

                    } else {
                        updateAlert(data.info);
                        setTimeout(function(){
                            $('#top-alert').find('button').click();
                            $(that).removeClass('disabled').prop('disabled',false);
                        },1500);
                    }
                }
                $('.span1').live('click',function () {
                //     $(this).parents('.answer').remove();
                // });
                // $('.span1').click(function () {
                    var id=$(this).attr('uid');
                    var index=$(this).index();
                    var str=$('#goods_img').val();
                    var arr=str.split(',');
                    var arr1=arr;
                    for ( var i = 0; i <arr.length; i++){
                        if(arr[i]==id){
                            arr1.splice(i,1);
                        }
                    }
                    $('#goods_img').val(arr1.join(','));
                    var index1=1;
                    if(index>1){
                        for (var i=2;i<index;i+=2){
                            index1++;
                        }
                    }
                    index=index-index1;
                    $('.span1').eq(index).remove();
                    $('.upload-pre-item').eq(index).remove();
                })
            </script>
        </div>
        <div class="form-item">
            <label class="item-label">商品详情</label>
            <div class="controls">
                <textarea id="container" name="introduce" ></textarea>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">运费</label>
            <div class="controls">
                 <input type="radio" name="freight" checked="checked" value="包邮">包邮
                 <input type="radio" name="freight" value="到付">到付
                 <input type="radio" name="freight" value="面议">面议
                 <input type="radio" name="freight" value="自理">自理
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">关键字</label>
            <div class="controls">
                 <input type="text" class="text input-large" name="keyword" value="">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">所属地区</label>
            <div class="controls">
                <input type="text" class="text input-large" name="goods_area" value="">
            </div>
        </div>
	   <div class="form-item">
           <input type="hidden" name="shop_id" value="{$shop_id}">
           <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
        //导航高亮
        highlight_subnav('{:U('Goods/index')}');
    </script>
    <!-- 配置文件 -->
    <script type="text/javascript" src="__STATIC__/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="__STATIC__/ueditor/ueditor.all.min.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
        var ue = UE.getEditor('container',{
            initialFrameWidth:"100%",
            initialFrameHeight:200,
            wordCount:false,
            autoHeightEnabled:false,
            autoFloatEnabled:false
        });
    </script>
</block>
